from datetime import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
from flask import Flask
from flask_restful import Api,Resource
from id24_closedoorspeed import *

result = {
        "precision rate and recall rate before Optimization":{"pre":precision_score(y_test,lrpred),"rec":recall_score(y_test,lrpred)},
        "best_params":best_params,
        "precision rate and recall rate after Optimization":{"pre":precision_score(y_test,blrpred),"rec":recall_score(y_test,blrpred)},
    }
app = Flask(__name__)
api = Api(app)
class HelloWorld(Resource):
    def get(self):
        print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        print("helloworld")
        return result
api.add_resource(HelloWorld, '/')   
def job():
    print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    print(result)

if __name__ == '__main__':
    scheduler = BlockingScheduler()
    scheduler.add_job(job, 'interval',  seconds=10)
    # scheduler.add_job(job, 'interval',  seconds=10, start_date='2021-08-16 17:44:00', end_date='2021-08-16 17:50:00')
    try:
        app.run(debug=True)
        scheduler.start()
        # scheduler.shutdown()
    except Exception as e:
        print(type(e),e)
